package ws.db.sql;
import ws.db.ColumnValuePair;

import java.util.ArrayList;
import java.util.Iterator;

public class InsertSQL extends SQL {

	protected ArrayList<ColumnValuePair> columnValues;
	
	
	public InsertSQL(String m_table,ArrayList<ColumnValuePair> m_columnValues){
		super(m_table);
		columnValues = m_columnValues;
	}
	
	
	
	
	/**
	 * Get the Insert SQL.
	 * @param:
	 * 		void
	 * @return:
	 * 		String - the insert SQL.
	 * */
	@Override
	public String getSQL() {
		// TODO Auto-generated method stub
		StringBuffer sql=new StringBuffer();
		sql.append("insert into ");
		sql.append(table);
		sql.append(" ( ");
		constructColumns(sql,columnValues);		
		sql.append(" ) ");
		sql.append(" values ");
		sql.append(" ( ");
		int t=1;
		Iterator its = columnValues.iterator();
		while(its.hasNext()){
			ColumnValuePair eachpair = (ColumnValuePair)its.next();
			sql.append("'");
			sql.append(eachpair.value);
			sql.append("'");
			if(t!=columnValues.size()){
				sql.append(",");
				t++;
			}
		}
		
		sql.append(" ) ");
		sql.append(";");
		return sql.toString();
	}

	
}
